<template>
	<div id="accountQQ">
		<div id="header">
			<img @click="$router.go(-1)" src="../../static/img/return.png"/>
			<p>绑定QQ账号</p>
		</div>
		<input type="text" placeholder="请输入你的QQ号" v-model="accountqq" />
		<input type="button" @click="update" value="确定" />
	</div>
</template>

<script>
export default{
	name: 'accountQQ',
	data:function(){
		return{
			accountqq: '',
		}
	},
	methods: {
		//--------获取用户绑定QQ-------
		getUserInfo: function(){
			var _this = this;
			this.$axios.post("/user/info/getBaseInfo").then(function(res){
				var data = res.data;
			    if(data.message == "succ"){
			    	_this.accountqq = data.result.qqAccount;
			    }else{
			    	_this.$alert(data.result);
			    }
			}
			).catch(function (error) {
				console.log(error);
			});
		},
		//--------修改QQ-------
		update: function(){
			var _this = this;
			var regx = /^[1-9][0-9]{4,14}$/;
			if(!_this.accountqq){
				_this.$alert("请输入QQ号");
				return;
			}
			if(!regx.test(_this.accountqq)){
				_this.$alert("请输入正确的QQ号");
				return;
			}
			let postData = _this.$qs.stringify({
				qq: _this.accountqq
			});
			this.$axios.post("/user/info/updateqq", postData).then(function(res){
				var data = res.data;
			    if(data.message == "succ"){
			    	_this.$alert("修改成功");
			    	_this.$router.go(-1);
			    }else{
			    	_this.$alert(data.result);
			    }
			}
			).catch(function (error) {
				console.log(error);
			});
		}
	},
	created: function(){
		this.getUserInfo();
	}
}
</script>

<style scoped>
/* ========== */
/* = Header = */
/* ========== */
#header{
	width: 100%;
	background-color: #fff;
	position: fixed;
	top: 0;
	left: 0;
	height: 4rem;
	display: flex;
	align-items: center;
	justify-content: center;
	border-bottom: 1px solid #EEEEEE;
	font-size: 1.6rem;
	color: #4F4F4F;
	box-sizing: border-box;
	z-index: 10;
}
#header img{
	height: 2rem;
	display: block;
	position: absolute;
	top: 1rem;
	left: 2rem;
}
#accountQQ{
	min-height: 100%;
	padding-top: 5rem;
	padding-bottom: 0.5rem;
	box-sizing: border-box;
	background-color: #fff;
}
input[type='text']{
	width: 90%;
	display: block;
	margin: 0 auto;
	border: 1px solid #EEEEEE;
	padding-left: 1rem;
	box-sizing: border-box;
	height: 3rem;
	font-size: 1.2rem;
}
input[type='button']{
	width: 90%;
	display: block;
	margin: 0 auto;
	border: none;
	box-sizing: border-box;
	height: 3rem;
	font-size: 1.2rem;
	background-color: #FF6565;
	color: #ffffff;
	margin-top: 1rem;
	letter-spacing: 1rem;
	padding-left: 1rem;
}
</style>